package com.snake.springboot.custom.controller.base;

import com.snake.springboot.custom.api.model.base.CustRoleModel;
import com.snake.springboot.custom.api.request.base.CustRoleQuery;
import com.snake.springboot.custom.api.request.page.PageQuery;
import com.snake.springboot.custom.api.service.base.CustRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.result.ReturnList;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>商户管理-商户角色
 * 类{@code CustRole} </br>
 * 创建时间2025/2/10 16:25
 *
 * @author yangxt
 * @see
 */
@Api(tags = "商户管理-商户角色")
@RestController
@RequestMapping("/cust/role")
public class CustRoleController {

    private CustRoleService custRoleService;
    @Autowired
    public CustRoleController(CustRoleService custRoleService) {
        this.custRoleService = custRoleService;
    }

    @ApiOperation("新增角色")
    @PostMapping("/add")
    public ResponseResult<CustRoleModel> addCustRole(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) CustRoleModel model) {
        CustRoleModel result = custRoleService.addCustRole(model);
        return ResponseResultFactory.ucc("添加成功！", result);
    }

    @ApiOperation("修改角色")
    @PostMapping("/modify")
    public ResponseResult<CustRoleModel> modifyCustRole(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody CustRoleModel model) {
        custRoleService.modifyCustRole(model);
        return ResponseResultFactory.ucc("修改成功！");
    }

    @ApiOperation("删除角色")
    @GetMapping("/remove/{id}")
    public ResponseResult<Object> remove(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @PathVariable("id") String id) {
        custRoleService.removeCustRole(id);
        return ResponseResultFactory.ucc("移除成功！");
    }

    @ApiOperation("查询角色")
    @PostMapping("/list")
    public ResponseResult<ReturnList<CustRoleModel>> queryCustRoleList(
            @ApiParam(name = "查询条件", value = "传入json类型", required = true)
            @RequestBody PageQuery<CustRoleQuery> params) {
        if (!StringUtils.isEmpty(params.getCustomId())){
            params.getParams().setCustomId(params.getCustomId());
        }
        ReturnList<CustRoleModel> result = custRoleService.queryCustRoleList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }


}
